﻿using Castle.MicroKernel.Registration;
using System.Reflection;

namespace Inovout.Business
{
    public class WorkItemInstaller : ComponentInstaller
    {
        public override void Register(Assembly assembly)
        {
             Container.Register(
             AllTypes.FromAssembly(assembly)
             .BasedOn<BaseWorkItem>()
             .WithService.Self()
             .WithService.AllInterfaces()
             .Configure(delegate(ComponentRegistration component)
                        {
                            component.LifeStyle.Transient
                                .OnCreate((kernel, instance) =>
                                {
                                    BaseWorkItem workItem = instance as BaseWorkItem;
                                    workItem.logger = Logger.Create(instance.GetType());
                                    workItem.viewData = kernel.Resolve<IViewDataDictionary>();
                                    workItem.guiAction = kernel.Resolve<IGuiAction>();
                                });
                        }
                    )
              );
        }
    }
}
